package com.library.admin.list;

import books.borrowing.entity.BookBorrowingEntity;

import com.library.admin.service.LibraryService;
import com.vaadin.ui.Table;

public class RentTable extends Table {
	private static final long serialVersionUID = 1L;
	private String subscriberLogin;
	
	public RentTable(String subscriberLogin) {
		this.subscriberLogin = subscriberLogin;
		init();
	}
	
	public void init() {
		setWidth("100%");
		setImmediate(true);
		setPageLength(0);
		
		addContainerProperty("ID",						String.class,     	null);
		addContainerProperty("ISBN",					String.class,     	null);
		addContainerProperty("Date d'emprunte",			String.class,  		null);
		addContainerProperty("Date de retour",			String.class,  		null);
		addContainerProperty("Login d'abonné",       	String.class, 		null);
		
		for (BookBorrowingEntity rent : LibraryService.getServiceBorrowing().findSubscriberRents(subscriberLogin)) {
			int itemId = rent.getId();
			
			addItem(new Object[] {rent.getId(), rent.getBookISBN(), rent.getRentDate(), rent.getReturnDate(),
					rent.getSubscriber().getLogin()}, itemId);
		}
	}
}
